package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.query.PjPubUpDealingsQuery;
import com.koron.css2.newProjectCenter.mapper.PjPubUpDealingsMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * @Author: 苏小龙
 * @CreateTime: 2024-12-03
 * @Description: 往来单位
 * @Version: 1.0
 */
public class PjPubUpDealingsDelete implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjPubUpDealingsQuery query = JsonUtils.objectToPojo(req.getData(), PjPubUpDealingsQuery.class);
            if (StringUtils.isBlank(query.getId())) {
                return MessageBean.create(Constant.MESSAGE_INT_FAIL, "ID 不能为空", null);
            }
            PjPubUpDealingsMapper pjPubUpInvoiceMapper = factory.getMapper(PjPubUpDealingsMapper.class);
            if (pjPubUpInvoiceMapper.hasDataById(query.getId()) > 0) {
                return MessageBean.create(Constant.MESSAGE_INT_FAIL, "该单位有相关数据，不能删除", null);
            }
            pjPubUpInvoiceMapper.deleteById(query.getId());
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "往来单位删除成功", null);
        } catch (Exception e) {
            logger.error("往来单位删除失败", e);
        }
        return MessageBean.create(Constant.MESSAGE_INT_FAIL, "往来单位删除失败", null);
    }
}
